<?php

// $Id$

require_once($WSC->get_site_inc_dir().'modules/admin_panel/site_admin_page_w_fctrl_ua.class.php');
require_once($WSC->get_site_inc_dir().'modules/admin_panel/forms/menu_item/menu_item_form_ctrl.class.php');


class Menu_Item_Edit_WP extends Site_Admin_Page_W_FCtrl_UA {
	protected function create_form_ctrl() {
		$dbc = $this->get_dbc();
		$tvm = $this->get_tvm();


		$context = $this->get__context();
		if ($context->exists_in_get('prefix')) {
			$prefix =  $context->get_from_get('prefix');
		} else {
			if ($context->exists_in_post('prefix')) {
				$prefix =  $context->get_from_post('prefix');
			} else {
				$prefix = '';
			}
		}

		$parent = false;
		if ($context->exists_in_get('parent')) {
			$parent =  $context->get_from_get('parent');
		}


		$ret = new Menu_Item_Form_Ctrl('menu_item', $tvm, $dbc, 'obj_id', $prefix, $parent);

		$this->export('prefix', $prefix);

		return $ret;
	}


	protected function on_add_new() {
		$context = $this->get__context();

		if ($context->exists_in_get('parent')) {
			$parent =  $context->get_from_get('parent');
		} else {
			throw new Tangra_User_Exception('Expecting parameter parent.');
		}


		if ($context->exists_in_get('prefix')) {
			$prefix =  $context->get_from_get('prefix');
		} else {
			$prefix = '';
		}

		$this->form_ctrl->prepare_order($context->get_from_get('parent'));

		$this->form_ctrl->set_permanent_external_param('prefix', $prefix);

//		$this->export('add_new', 1);
	}


	protected function on_received_id($object_id) {
		$context = $this->get__context();
		if ($context->exists_in_get('prefix')) {
			$prefix =  $context->get_from_get('prefix');
		} else {
			$prefix = '';
		}

		$this->form_ctrl->set_permanent_external_param('prefix', $prefix);

//		$this->export('site_id', $object_id);
	}


	protected function create_redir_view() {
		$redir = new Redirect_Composer_Local($this->get__context(), $this->get_redir_on_success());
		$prefix = $this->form_ctrl->get_permanent_external_param('prefix');;
		$redir->add_param_pair('prefix', $prefix);
		$redir_view = new Just_Headers_View();
		$redir_view->add_http_header($redir->get_location($this->get__context()));

		return $redir_view;
	}

}